/*
 * @Descripttion:
 * @version: 1.0
 * @Author: xin
 * @Date: 2021-10-14 19:51:11
 * @LastEditors: serve
 * @LastEditTime: 2021-10-14 20:05:13
 */

var mg = require('../db/userdb')
var pr_mg = require('../db/processdb')
var msg = require('../tool/message')
var redis = require('../db/redis')
var pu = require('../tool/public')
var flow_db = require('../db/flowdb')


class circle {
    /*
* 流程流转
* @param data 要查找的流程数据
* @param id 下流程的id
* @param name 下流程的名字
* */
    async circulation(data,next_temp_condition){
        var flow = data.flow
        var line = data.line
        if(data.next_process_status === 1){
            let info = await flow_db.findOne('flow_temp', { temp_id: flow_db.ObjectID(data.next_process_id), name: data.next_process_name })
            if(data.new_tatus === 1){
                var update = {new_tatus:0}
                //触发下流程
                await flow_db.updateOne('flow_temp', { _id: flow_db.ObjectID(info._id) }, { $set: update })
            }
            if(info){
                condition(next_temp_condition,info)
                // circulation(info)
            }
        }
        flow.forEach((item,index)=>{
            line.forEach((v,i)=>{
                // if(item.){
                //
                // }
            })
        })
    }
    /*
    * 条件判断
    * @param data 条件
    * @param flow 流程数据
    * */
    condition(data,flow){
        var everyIndex = data.lastIndexOf('every')
        var value = ''
        var arr = []
        var lastIndex = ''
        var lastValue = ''
        var conditionData = ['>','<','=','!=','>=','<=','']
        if(dataIndex){
            value = data.splice(everyIndex,data.length)
            if(value){
                flow.flow.forEach((v,i)=>{
                    if(v.value === value){
                        arr.push(true)
                    }else{
                        arr.push(false)
                    }
                })
            }
            if(arr.every(item => item === true)){
            //   条件满足触发下流程
            }

        }else{
            conditionData.forEach((item)=>{
                lastIndex = data.lastIndexOf(item)
                if(lastIndex){
                    lastValue = data.splice(lastIndex,data.length)

                }
            })
        }
    }
}
// console.log(circle());
module.exports = new circle()
